<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>cloneWith</title>
  <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.js"></script>
</head>

<body>
  <script>
    // 定义一个包含函数的对象
    const originalObject = [
      {
        name: "Alice",
        cloneMethod: (value) => `Cloned: ${value}`, // 自定义克隆逻辑
      },
      {
        name: "Bob",
        cloneMethod: null, // 使用默认克隆逻辑
      },
    ];

    // 自定义复制函数，只复制字符串类型的属性值
    function customizer (value) {
      console.log(value);
      if (_.isFunction(value.cloneMethod)) {
        console.log('123');
        // 如果对象有自定义的克隆方法，则使用它
        return value.cloneMethod(value.name);
      }
      // 否则，使用默认的克隆逻辑
      return _.cloneDeep(value);
    }

    // 使用自定义复制函数进行复制
    const clonedObject = _.cloneWith(originalObject, customizer);

    console.log(clonedObject, clonedObject[0].cloneMethod());
  </script>
</body>

</html>